package ooday03;

public class Test {
    public static void main(String[] args) {
        Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("小黑", 2, "黑");
        dogs[1] = new Dog("大黄", 1, "黄");
        dogs[2] = new Dog("小灰", 3, "灰");
        System.out.println(dogs[0].name);
        dogs[1].age = 4;
        dogs[2].swim();
        for (int i = 0; i < dogs.length; i++) {
            System.out.println(dogs[i].name);
            dogs[i].eat();
        }


        Fish[] fish = new Fish[2];
        fish[0] = new Fish("小金鱼", 2, "金");
        fish[1] = new Fish("小花鱼", 3, "花");
        for (int i = 0; i < fish.length; i++) {
            System.out.println(fish[i].name);
            fish[i].eat();

        }

        Chick[] chicks = new Chick[2];
        chicks[0] = new Chick("小花", 2, "黑");
        chicks[1] = new Chick("大花", 3, "红");
        for (int i = 0; i < chicks.length; i++) {
            System.out.println(chicks[i].name);
            chicks[i].eat();


            Dog dog =new Dog("小蓝",3,"蓝");
            System.out.println(dog.name);
            dog=null;
            //System.out.println(dog.name);地址被赋为空，空指针异常
            //因此在数组中每个对象都要赋值

        }

    }

}
